package com.september.prop;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;



public class Properteer {
	private static Properteer properteer;
	private static  Properties properties;
	private static Logger logger;
	
	static {
		PropertyConfigurator.configure(Properteer.class.getClassLoader().getResourceAsStream("log4j.properties"));
		logger = Logger.getLogger(Properteer.class);
		
		properties = new Properties();
		
		try {
			properties.load(Properteer.class.getClassLoader().getResourceAsStream("rest.properties"));
			properties.load(Properteer.class.getClassLoader().getResourceAsStream("data.properties"));
			properties.load(Properteer.class.getClassLoader().getResourceAsStream("auth.properties"));
						
		} catch (IOException e) {
			logger.error(e.getMessage(),e);
		}
	}
	
	private Properteer() {
		
	}
	
	public static void inject(InputStream is) {
		try {
			properties.load(is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			logger.error(e.getMessage(), e);
		}
	}	
	public static Properties Properties() {
		return properties;
	}
	
	public static Properteer getInstance() {
		if (properteer == null) properteer = new Properteer();
		return properteer;
	}
	
	public Logger getLogger(Class caller) {
		return Logger.getLogger(caller);
	}

}
